<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>编辑资料</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">

    <link rel="stylesheet" href="/sunfc/css/weui.min.css">
    <link rel="stylesheet" href="/sunfc/css/style.css">
    <link rel="stylesheet" href="/res/layui/css/layui.css" media="all">
    <script src="/res/layui/layui.js"></script>
    <style>
        .weui-cell{height:40px}
        .weui-media-box {
            padding: 0px;
        }
        .weui-label{
            width:50px;color: #8C8C8C
        }
        ::-webkit-input-placeholder{
            color: #C3C3C3;
        }

    </style>
</head>
<body  style="background:#f4f4f4">
<div class="index-top">
    <div class="index-back">
        <a href="{:url('index/sunfc.users/index')}" style="color: #4b5361">
            取消
        </a>
    </div>
    <p class="index-title">编辑资料</p>
    <div class="index-right" id="submit">
        完成
    </div>
</div>

<!-- 这里写内容 -->

<div class="weui-panel__bd"  style="margin-top:40px;background:white">
    <!--<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg"  style="height:80px">-->
        <!--<div class="weui-media-box__hd" style="width:25%;">-->
            <!--<img class="weui-media-box__thumb"   style="width:60px;height:60px;border-radius:40px;" src="{$result.headimgurl}">-->
        <!--</div>-->

        <!--<div class="weui-media-box__bd">-->
            <!--<p class="weui-media-box__desc"   style="margin-top:5px;">修改头像</p>-->
        <!--</div>-->
    <!--</a>-->
    <div class="layui-form-item" style="padding-top: 15px;text-align: center">

        <div class="layui-input-inline " style="width: auto; margin: 0px">
            <div class="layui-upload-drag" id="avatar" style="padding: 2px;border-radius: 100%">
                <img class="layui-upload-img" style="width:60px;height:60px;border-radius:40px;" src="{$result.avatar}">
                <input type="hidden" value="{$result.headimgurl}" >
            </div>


        </div>
        <span style="padding-right: 4px">修改头像</span>
    </div>
    <div class="weui-cell"   >
        <div class="weui-cell__hd"><label class="weui-label"   >昵称</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="nickname" placeholder="请输入你的昵称" value="{$result.nickname}">
            <!--<span   style="color: #383838;font-weight: bold;">{$result.nickname}</span>-->
        </div>
    </div>
    <div class="weui-cell"   >
        <div class="weui-cell__hd"><label class="weui-label"  >性别</label></div>
        <div class="weui-cell__bd">
            <!--<span   style="color: #383838;font-weight: bold">男</span>-->
            <select class="weui_select" id="sex" style="width: 100%;outline: 0;border: 0;color: #4b5361;font-weight: bold">
                {if condition="$result.sex == 1"}
                <option selected="" value="1">男</option>
                <option value="2">女</option>
                <option value="0">保密</option>
                {elseif condition="$result.sex == 2"/}
                <option  value="1">男</option>
                <option selected="" value="2">女</option>
                <option value="0">保密</option>
                {else /}
                <option  value="1">男</option>
                <option  value="2">女</option>
                <option  selected="" value="0">保密</option>
                {/if}

            </select>
        </div>
    </div>
</div>


<div style="background:white;margin-top:20px">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label" >公司</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="company" placeholder="添加所在公司" value="{$result.company}">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label" >职业</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="profession"  placeholder="添加所在职业" value="{$result.profession}">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label" style="width:80px;color: #8C8C8C">个性签名</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" id="autograph" placeholder="还未填写个性签名，简单介绍一下自己吧" value="{$result.autograph}">
        </div>
    </div>
</div>

<div style="pt40">
</div>
<script src="/sunfc/js/jquery.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>



    wx.config({
        debug: false,
        appId: '{$jsconfig.appId}',
        timestamp: '{$jsconfig.timestamp}',
        nonceStr: '{$jsconfig.noncestr}',
        signature: '{$jsconfig.signature}',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onRecordEnd',
            'playVoice',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });
    wx.isInit = false;

    wx.ready(function () {



        // 5 图片接口
        // 5.1 拍照、本地选图
        var images = {
            localId: [],
            serverId: []
        };




        $('#avatar').click(function () {
            wx.chooseImage({
                success: function (res) {
                    images.localId = res.localIds;
                    console.log('已选择 ' + res.localIds.length + ' 张图片');
                    var i = 0, length = images.localId.length;
                    images.serverId = [];
                    function upload() {
                        wx.uploadImage({
                            localId: images.localId[i],
                            success: function (res) {

                                i++;
                                console.log('已上传：' + i + '/' + length);
                                //单个上传完成时
//                                record.send_img(res.serverId);

                                $.get('/index/api/tempfile', {mid: res.serverId}, function (res) {
                                    console.log(res);
                                    if(res.code==1){
                                        //app.items.push(res.data);
                                        $('#avatar img').attr('src',res.data.src);
                                        $('#avatar input').val(res.data.src);


                                    }
                                });

                                images.serverId.push(res.serverId);
                                if (i < length) {
                                    upload();
                                } else {
                                    //全部上传完成时


                                }
                            },
                            fail: function (res) {
                                alert(JSON.stringify(res));
                            }
                        });
                    }

                    upload();

                }
            });
        });






    });

    wx.error(function (res) {
        alert(res.errMsg);
    });


</script>
<script>
    // 点击完成上传数据
    $(document).ready(function () {
        $('#submit').click(function () {
            var user_avatar =   $('#avatar input').val();
            var user_nickname   =  $('#nickname').val();
            var user_sex    =   $('#sex').val();
            var user_company    =   $('#company').val();
            var user_profession =    $('#profession').val();
            var user_autograph  = $('#autograph').val();
            //alert("头像："+user_avatar+"--昵称:"+user_nickname+"--性别:"+user_sex+"--公司:"+user_company+"--职业:"+user_profession+"--个性签名:"+user_autograph);
            $.post("{:url('sunfc.users/messedit')}",
                {
                    headimgurl:user_avatar,
                    nickname:user_nickname,
                    sex:user_sex,
                    company:user_company,
                    profession:user_profession,
                    autograph:user_autograph
                },
                function(data){
                    if(data.code==1){
                        alert(data.msg);
                        window.location.href="{:url('index/sunfc.users/index')}";
                    }else {
                        alert(data.msg);
                    }
                });
        })
    })
</script>
<!--<script>-->
    <!--layui.use('upload', function(){-->
        <!--var upload = layui.upload;-->

        <!--//执行实例-->
        <!--var uploadInst = upload.render({-->
            <!--elem: '#avatar' //绑定元素-->
            <!--,url: '/tool/qiniu/upload'-->
            <!--,before:function () {-->
                <!--layer.load(2);-->
            <!--}-->
            <!--,done: function(res){-->
                <!--layer.closeAll();-->
                <!--console.log(res)-->
                <!--$('#avatar img').attr('src',res.data.url);-->
                <!--$('#avatar input').val(res.data.url);-->
            <!--}-->
        <!--});-->
    <!--});-->
<!--</script>-->
</body>
</html>
